package com.xiaoyu.utils;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LocalFilter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //登录检查逻辑
        HttpSession session = request.getSession();

        Object loginAccount = session.getAttribute("loginAccount");

        if(loginAccount != null){
            //放行
            return true;
        }
        //拦截住。未登录。跳转到登录页
        request.getRequestDispatcher("/null");
        return false;
    }
}
